package org.jeecg.modules.jxc.goodstype.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.models.auth.In;
import org.jeecg.modules.jxc.goodstype.entity.JxcGoodsType;
import org.jeecg.modules.jxc.goodstype.mapper.JxcGoodsTypeMapper;
import org.jeecg.modules.jxc.goodstype.service.JxcGoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @company: yaorange
 * @author: Mr.Yu
 * @version: 1.0
 * @create: 2021-12-21 09:40:03
 */

@Service
public class JxcGoodsTypeServiceImpl implements JxcGoodsTypeService {

    @Autowired
    private JxcGoodsTypeMapper goodsTypeMapper;

    private static final Integer NUMBER_P = -1;

    private static final String PID="p_id";

    private static String keys="children";

    @Override
    public List<Map<String,Object>> selectByList() {
        //查询父节点
        List<Map<String, Object>> jxcGoodsType = goodsTypeMapper.selectGoodsList(NUMBER_P.toString());

        //查询第二级节点
        String typeId = String.valueOf(jxcGoodsType.get(0).get("key"));
        List<Map<String,Object>> list = goodsTypeMapper.selectGoodsList(typeId);



        //查询第三级节点
        for (int i = 0; i < list.size(); i++) {
            String key = String.valueOf(list.get(i).get("key"));
            List<Map<String, Object>> mapList = goodsTypeMapper.selectGoodsList(key);
            list.get(i).put(keys,mapList);
        }
        jxcGoodsType.get(0).put(keys,list);
        return jxcGoodsType;
    }

    @Override
    public List<JxcGoodsType> selectTree() {
        List<JxcGoodsType> list = goodsTypeMapper.selectTree();
        return list;
    }

    @Override
    public List<JxcGoodsType> selectById(String id) {

        List<JxcGoodsType> list=goodsTypeMapper.selectChildren(id);
        return list;
    }

}
